Gyazo Viewer Page Menu
api.gyazo.com無いよね
https://gyazo.com/ec9d457a8006b9ff5d120aa807005cf9
ぐぬう…
firefoxでも無理だったぞ
code:script.js
const id = 'Gyazo Viewer';
export function addGyazoMenu({GYAZO_ACCESS_TOKEN, imageNum, theme = 'light'} = {}) {
scrapbox.PageMenu.addMenu({
title: id,
onClick: () => loadGyazoImages({GYAZO_ACCESS_TOKEN, imageNum, theme}),
});
}
async function loadGyazoImages({GYAZO_ACCESS_TOKEN, imageNum, theme}) {
let timer = null;
try {
const promise = fetch(https://api.gyazo.com/api/images?access_token=${GYAZO_ACCESS_TOKEN}&per_page=${imageNum});
// 読み込みに時間がかかるようであれば、読み込み中の表示を出す
timer = setTimeout(() => {
scrapbox.PageMenu(id).addItem({
title: 'Loading...',
image: https://img.icons8.com/ios/180/${theme === 'dark' ? 'FFFFFF/' : ''}loading.png,
onClick: () => {},
})},
100);
const res = await promise;
const images = await res.json();
clearTimeout(timer);
scrapbox.PageMenu(id).removeAllItems();
images.filter(image => image.image_id !== '')
.forEach(image =>
scrapbox.PageMenu(id).addItem({
title: image.metadata.title ?? 'Untitled',
image: image.url,
onClick: () => navigator?.clipboard?.writeText?.(image.permalink_url),
})
);
} catch(e) {
clearTimeout(timer);
scrapbox.PageMenu(id).removeAllItems();
scrapbox.PageMenu(id).addItem({
title: 'Failed to load the image list.',
image: https://i.gyazo.com/9fb0ce04c8ce55890f1388e21f36dccc.png,
onClick: () => {},
});
console.log('Failed to load the image list. %o',e);
}
}